package chessman;

import java.util.ArrayList;

import javax.swing.ImageIcon;

public class Queen extends Chessman {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1347648402561644092L;
	private static Queen instanceA = new Queen(new ImageIcon("Resources/Images/Queen-icon.png"),0);
	private static Queen instanceB = new Queen(new ImageIcon("Resources/Images/Queen-blue-icon.png"),1);
		public static Queen getInstanceTeamA(){
			return instanceA;
		}
		public static Queen getInstanceTeamB(){
			return instanceB;
		}
	public Queen(ImageIcon icon, int team) {
		super(icon, team);
		// TODO Auto-generated constructor stub
	}

	@Override
	public ArrayList<String> canMove(Chessman[] arrayChess) {
		ArrayList<String> moves = new ArrayList<String>();
		String temp = null;
		Chessman c = null;
		for (int i = 1; i < 8; i++) {
			if(this.row - i >= 0 && this.col - i >=0){
				c = arrayChess[ (this.row - i) * 8 + this.col - i];
				if( c != null){
					if(this.isSameTeam(c)){
						break;
					}
					else{
						temp = this.cols[this.col - i]+this.rows[this.row - i];
						moves.add(temp);
						break;
					}
				}
				else{
					temp = this.cols[this.col - i]+this.rows[this.row - i];
					moves.add(temp);
				}
			}
			else{
				break;
			}
			
			
		}
		for (int i = 1; i < 8; i++) {
			if(this.row + i < 8 && this.col - i >=0){
				c = arrayChess[ (this.row + i) * 8 + this.col - i];
				if( c != null){
					if(this.isSameTeam(c)){
						break;
					}
					else{
						temp = this.cols[this.col - i]+this.rows[this.row + i];
						moves.add(temp);
						break;
					}
				}
				else{
					temp = this.cols[this.col - i]+this.rows[this.row + i];
					moves.add(temp);
				}
			}
			else{
				break;
			}
			
			
		}
		
		for (int i = 1; i < 8; i++) {
			if(this.row - i >= 0 && this.col + i < 8){
				c = arrayChess[ (this.row - i) * 8 + this.col + i];
				if( c != null){
					if(this.isSameTeam(c)){
						break;
					}
					else{
						temp = this.cols[this.col + i]+this.rows[this.row - i];
						moves.add(temp);
						break;
					}
				}
				else{
					temp = this.cols[this.col + i]+this.rows[this.row - i];
					moves.add(temp);
				}
			}
			
		}
		for (int i = 1; i < 8; i++) {
			if(this.row + i < 8 && this.col + i < 8){
				c = arrayChess[ (this.row + i) * 8 + this.col + i];
				if( c != null){
					if(this.isSameTeam(c)){
						break;
					}
					else{
						temp = this.cols[this.col + i]+this.rows[this.row + i];
						moves.add(temp);
						break;
					}
				}
				else{
					temp = this.cols[this.col + i]+this.rows[this.row + i];
					moves.add(temp);
				}
			}
			else{
				break;
			}
		}
		for(int i=this.row+1;i<8;i++){
			c = arrayChess[i * 8 + this.col]; 
			if( c != null){ // co can duong
				if(this.isSameTeam(c)){ // cung team thi khong cho qua
					break;
				}
				else{ // khac team thi co the an len
					temp = this.cols[this.col]+this.rows[i];
					moves.add(temp);
					break;
				}
				
			}
			else{ // khong co can duong
				temp = this.cols[this.col]+this.rows[i];
				moves.add(temp);
			}
			
		}
		for(int i=this.row - 1;i >= 0;i--){
			c = arrayChess[i * 8 + this.col]; 
			if( c != null){ // co can duong
				if(this.isSameTeam(c)){ // cung team thi khong cho qua
					break;
				}
				else{ // khac team thi co the an len
					temp = this.cols[this.col]+this.rows[i];
					moves.add(temp);
					break;
				}
				
			}
			else{ // khong co can duong
				temp = this.cols[this.col]+this.rows[i];
				moves.add(temp);
			}
		}
		for(int i=this.col -1;i>=0;i--){
			c = arrayChess[this.row * 8 + i]; 
			if( c != null){ // co can duong
				if(this.isSameTeam(c)){ // cung team thi khong cho qua
					break;
				}
				else{ // khac team thi co the an len
					temp = this.cols[i]+this.rows[this.row];
					moves.add(temp);
					break;
				}
			}
			else{
				temp = this.cols[i]+this.rows[this.row];
				moves.add(temp);
			}
			
		}
		for(int i=this.col+1;i<8;i++){
			c = arrayChess[this.row * 8 + i]; 
			if( c != null){ // co can duong
				if(this.isSameTeam(c)){ // cung team thi khong cho qua
					break;
				}
				else{ // khac team thi co the an len
					temp = this.cols[i]+this.rows[this.row];
					moves.add(temp);
					break;
				}
			}
			else{
				temp = this.cols[i]+this.rows[this.row];
				moves.add(temp);
			}
		}
		
		return moves;
	}

}
